package com.zhiche.lisa.bms.controller.psup;


import com.baomidou.mybatisplus.plugins.Page;
import com.zhiche.lisa.bms.dao.model.psup.PsupTraditionPrice;
import com.zhiche.lisa.bms.pojo.vo.common.CommonVO;
import com.zhiche.lisa.bms.pojo.vo.psup.PsupTraditionPriceVO;
import com.zhiche.lisa.bms.service.psup.PsupTraditionPriceService;
import com.zhiche.lisa.core.supports.BaseException;
import com.zhiche.lisa.core.supports.RestfulResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 人送传统价格管理 前端控制器
 * </p>
 *
 * @author linbao
 * @since 2019-06-18
 */
@RestController
@RequestMapping("/psupTraditionPrice")
@Api(description = "人送传统价格管理", tags = "人送传统价格管理")
@Slf4j
public class PsupTraditionPriceController extends PsupSdBaseController {

    @Autowired
    private PsupTraditionPriceService psupTraditionPriceService;

    /**
     * 分页查询
     *
     * @return
     */
    @PostMapping(value = "/querySdTraditionPricePage")
    @ApiOperation(value = "人送传统价格分页查询", notes = "人送传统价格分页查询", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "success", response = PsupTraditionPriceVO.class),
            @ApiResponse(code = -1, message = "系统异常")})
    public RestfulResponse<Page<PsupTraditionPriceVO>> querySdTraditionPricePage(@RequestBody Page<PsupTraditionPrice> page) {
        log.info("PsupTraditionPriceController.querySdTraditionPricePage param: {}", page);
        RestfulResponse<Page<PsupTraditionPriceVO>> resultResponse = getSuccessResponse();
        try {
            resultResponse.setData(psupTraditionPriceService.querySdTraditionPricePage(page));
        } catch (BaseException e) {
            log.error("PsupTraditionPriceController.querySdTraditionPricePage error:{}", e);
            setBaseExceptionResponse(resultResponse, e.getMessage());
        } catch (Exception e) {
            log.error("PsupTraditionPriceController.querySdTraditionPricePage error:{} ", e);
            setErrorResponse(resultResponse);
        }
        return resultResponse;
    }

    /**
     * 根据id获取人送传统价格
     *
     * @return
     */
    @GetMapping(value = "/getSdTraditionPriceById/{id}")
    @ApiOperation(value = "根据id获取人送传统价格", notes = "根据id获取人送传统价格", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "success", response = RestfulResponse.class),
            @ApiResponse(code = -1, message = "系统异常")})
    public RestfulResponse<PsupTraditionPrice> getSdTraditionPriceById(@PathVariable("id") Long id) {
        log.info("PsupTraditionPriceController.getSdTraditionPriceById param: {}", id);
        RestfulResponse<PsupTraditionPrice> resultResponse = getSuccessResponse();
        try {
            resultResponse.setData(psupTraditionPriceService.selectById(id));
        } catch (BaseException e) {
            log.error("PsupTraditionPriceController.getSdTraditionPriceById error:{}", e);
            setBaseExceptionResponse(resultResponse, e.getMessage());
        } catch (Exception e) {
            log.error("PsupTraditionPriceController.getSdTraditionPriceById error:{} ", e);
            setErrorResponse(resultResponse);
        }
        return resultResponse;
    }

    /**
     * 人送基础信息的修改
     *
     * @return
     */
    @PostMapping(value = "/updateSdTraditionPrice")
    @ApiOperation(value = "人送传统价格的修改", notes = "人送传统价格的修改", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "success", response = RestfulResponse.class),
            @ApiResponse(code = -1, message = "系统异常")})
    public RestfulResponse<Object> updateSdTraditionPrice(@RequestBody PsupTraditionPriceVO psupTraditionPriceVO) {
        log.info("PsupTraditionPriceController.updateSdTraditionPrice param: {}", psupTraditionPriceVO);
        RestfulResponse<Object> resultResponse = getSuccessResponse();
        try {
            psupTraditionPriceService.updateTraditionPice(psupTraditionPriceVO);
        } catch (BaseException e) {
            log.error("PsupTraditionPriceController.updateSdTraditionPrice error:{}", e);
            setBaseExceptionResponse(resultResponse, e.getMessage());
        } catch (Exception e) {
            log.error("PsupTraditionPriceController.updateSdTraditionPrice error:{} ", e);
            setErrorResponse(resultResponse);
        }
        return resultResponse;
    }

    /**
     * 批量审核
     *
     * @return
     */
    @PostMapping(value = "/auditTraditionPriceByIdList")
    @ApiOperation(value = "人送传统价格批量审核", notes = "人送传统价格批量审核", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "success"), @ApiResponse(code = -1, message = "系统异常")})
    public RestfulResponse<Object> auditTraditionPriceByIdList(@RequestBody CommonVO<Long> commonVO) {
        log.info("PsupTraditionPriceController.auditTraditionPriceByIdList param: {}", commonVO);
        RestfulResponse<Object> resultResponse = getSuccessResponse();
        try {
            if (Objects.isNull(commonVO) || CollectionUtils.isEmpty(commonVO.getEntityParams())) {
                throw new BaseException("参数为空, 请选择数据!");
            }
            List<String> resultMst = psupTraditionPriceService.auditTraditionPrice(commonVO.getEntityParams());
            if (CollectionUtils.isNotEmpty(resultMst)) {
                setErrorListResponse(resultResponse, resultMst);
                return resultResponse;
            }
        } catch (BaseException e) {
            log.error("PsupTraditionPriceController.auditTraditionPriceByIdList error:{}", e);
            setBaseExceptionResponse(resultResponse, e.getMessage());
        } catch (Exception e) {
            log.error("PsupTraditionPriceController.auditTraditionPriceByIdList error:{} ", e);
            setErrorResponse(resultResponse);
        }
        return resultResponse;
    }

    /**
     * 批量删除
     *
     * @return
     */
    @PostMapping(value = "/deleteBatchTraditionPrice")
    @ApiOperation(value = "人送传统价格批量删除", notes = "人送传统价格批量删除", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "success"), @ApiResponse(code = -1, message = "系统异常")})
    public RestfulResponse<Object> deleteBatchTraditionPrice(@RequestBody CommonVO<Long> commonVO) {
        log.info("PsupTraditionPriceController.deleteBatchTraditionPrice param: {}", commonVO);
        RestfulResponse<Object> resultResponse = getSuccessResponse();
        try {
            if (Objects.isNull(commonVO) || CollectionUtils.isEmpty(commonVO.getEntityParams())) {
                throw new BaseException("参数为空, 请选择数据!");
            }
            psupTraditionPriceService.deleteBatchByIdList(commonVO.getEntityParams());
        } catch (BaseException e) {
            log.error("PsupTraditionPriceController.deleteBatchTraditionPrice error:{}", e);
            setBaseExceptionResponse(resultResponse, e.getMessage());
        } catch (Exception e) {
            log.error("PsupTraditionPriceController.deleteBatchTraditionPrice error:{} ", e);
            setErrorResponse(resultResponse);
        }
        return resultResponse;
    }
}

